package threadings;

/**
 * Created with IntelliJ IDEA.
 * Description:单例模式  饿汉模式
 * User: yyx
 * Date: 2024-02-04
 * Time: 16:57
 */
class Singleton{
    private static Singleton singleton = new Singleton();

    public static Singleton getSingleton() {
        return singleton;
    }
    //将构造方法设置为private禁止外部重新创建
    public Singleton(){
        //空着就行
    }
}
public class ThreadDemo12 {
    public static void main(String[] args) {
        Singleton s1 = Singleton.getSingleton();
        Singleton s2 = Singleton.getSingleton();
//        外部不允许再new这个类的实例
//        Singleton s3 = new Singleton();
    }
}
